/**
 * Created on Apr 22, 2007
 */
package x.java.io;

import java.io.FileDescriptor;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.MalformedURLException;

/**
 * @author qiangli
 *
 */
public class FileReader extends java.io.FileReader {
	protected InputStreamReader isr = null;
	protected x.java.io.File file = null;
	/**
	 * @param file
	 * @throws FileNotFoundException
	 */
	public FileReader(java.io.File file) throws FileNotFoundException {
		super(new FileDescriptor());
		this.file = (x.java.io.File)file;
		this.file.checkReadable();
		try {
			this.isr = new InputStreamReader(file.toURI().toURL().openStream());
		} catch (MalformedURLException e) {
			e.printStackTrace();
			throw new FileNotFoundException(file.toURI().toString());
		} catch (IOException e) {
			throw new RuntimeException(e);
		}
	}

	/**
	 * @param fileName
	 * @throws FileNotFoundException
	 */
	public FileReader(String fileName) throws FileNotFoundException {
		this(new File(fileName));
	}

	public void close() throws IOException {
		isr.close();
	}

	public String getEncoding() {
		return isr.getEncoding();
	}

	public int read() throws IOException {
		return isr.read();
	}

	public int read(char[] cbuf, int offset, int length) throws IOException {
		return isr.read(cbuf, offset, length);
	}

	public boolean ready() throws IOException {
		return isr.ready();
	}

	public void mark(int readAheadLimit) throws IOException {
		isr.mark(readAheadLimit);
	}

	public boolean markSupported() {
		return isr.markSupported();
	}

	public int read(char[] cbuf) throws IOException {
		return isr.read(cbuf);
	}

	public void reset() throws IOException {
		isr.reset();
	}

	public long skip(long n) throws IOException {
		return isr.skip(n);
	}

	public java.io.File getFile() {
		return this.file;
	}
	
}
